﻿//create the XMLHTTP object in different browsers
function getXMLHTTP( ) {
    var XMLHTTP = null;
    if (window.ActiveXObject) 
    {
        try {
            XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e)
        {
            try {
                XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            }
        }
    } 
    else if (window.XMLHttpRequest) {
        try {
            XMLHTTP = new XMLHttpRequest( );
        } catch (e) {
        }
    }
    return XMLHTTP;
}

var XMLHTTP = getXMLHTTP( );

//send get request
function sendGetRequest(url)
{
    if (XMLHTTP != null) {
        XMLHTTP.open("GET", url);
        XMLHTTP.onreadystatechange = stateChanged;
        XMLHTTP.send(null);
    }
}

//send post request
function sendPostRequest(url,parameterpairs)
{
    if (XMLHTTP != null) {
        XMLHTTP.open("POST", url);
        XMLHTTP.onreadystatechange = stateChanged;
        XMLHTTP.send(parameterpairs);
    }
}

//function stateChanged() should be implement in host file.
//function stateChanged() {
//    if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) {
//        alert(XMLHTTP.responseText);
//    }
//}